package com.team.service.impl;

import com.team.dao.AdminMapper;
import com.team.dao.ReservationMapper;
import com.team.dao.SectionMapper;
import com.team.entity.Section;
import com.team.service.StatisticalService;
import com.team.vo.Result;
import com.team.vo.StatisticalVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * -*- coding:utf-8 -*-
 *
 * @author 太阳偷渡青山
 * @software IntelliJ IDEA
 * @date 2022/10/21 17:32
 * @Description
 */
@Service
public class StatisticalServiceImpl implements StatisticalService {

    @Autowired
    private AdminMapper adminMapper;

    @Override
    public Result sectionInfo() {
        List<StatisticalVo> list = adminMapper.selectAllInfo();
        return new Result(200,"统计科室所有在职信息",list);
    }

    @Override
    public Result eduInfo() {
        List<StatisticalVo> list = adminMapper.eduInfo();
        Map<String,List<Object>> map = new HashMap<>(2);
        List<Object> edu = new ArrayList<>();
        List<Object> eduInfo = new ArrayList<>();
        for (StatisticalVo vo : list) {
            edu.add(vo.getName());
            eduInfo.add(vo.getValue());
        }
        map.put("edu",edu);
        map.put("eduInfo",eduInfo);
        return new Result(200,"查询学历信息成功",map);
    }

    @Autowired
    private ReservationMapper reservationMapper;

    @Override
    public Result reservationInfo() {
        List<StatisticalVo> list = reservationMapper.reservationInfo();
        System.out.println("--------------------------------------------");
        System.out.println("data"+list);
        Map<String,List> map = new HashMap<>(2);
        List<Object> reservation = new ArrayList<>();
        System.out.println("name"+reservation);
        List<Object> reservationInfo = new ArrayList<>();
        System.out.println("value"+reservationInfo);
        List<BigDecimal> reservationTotal = new ArrayList<>();
        System.out.println("total"+reservationTotal);

        for (StatisticalVo vo : list) {
            reservation.add(vo.getName());
            reservationInfo.add(vo.getValue());
            reservationTotal.add(vo.getTotal());
        }
        map.put("name",reservation);
        map.put("value",reservationInfo);
        map.put("total",reservationTotal);
        map.put("data",list);
        return new Result(200,"查询学历信息成功",map);
    }

    @Override
    public Result userInfo() {
        List<StatisticalVo> list = reservationMapper.userInfo();
        Map<String,List> map = new HashMap<>(4);
        List<String> user = new ArrayList<>();
        List<String> userInfo = new ArrayList<>();
        List<BigDecimal> userTotal = new ArrayList<>();

        for (StatisticalVo vo : list) {
            user.add(vo.getName());
            userInfo.add(vo.getValue());
            userTotal.add(vo.getTotal());
        }

        map.put("name",user);
        map.put("value",userInfo);
        map.put("total",userTotal);
        map.put("data",list);
        return new Result(200,"查询学历信息成功",map);
    }

    @Autowired
    private SectionMapper sectionMapper;

    @Override
    public Result priceInfo() {
        List<Section> sections = sectionMapper.selectAllName();
        List<String> sectionName = new ArrayList<>();
        for (Section section : sections) {
            sectionName.add(section.getName());
        }

        List<StatisticalVo> list = reservationMapper.selectByTotalPrice();

        List<Object> date = new ArrayList<>();
        List<Object> price = new ArrayList<>();
        for (StatisticalVo vo : list) {
            date.add(vo.getDate());
            price.add(vo.getTotal());
        }

        List<Map> series = new ArrayList<>();

        for (Section section : sections) {
            Map<String,Object> map = new HashMap<>();
            List<BigDecimal> data = new ArrayList<>();
            for (StatisticalVo vo : list) {
                BigDecimal decimals = reservationMapper.selectBySidDate(vo.getDate(), section.getId());
                data.add(decimals);
            }
            map.put("name",section.getName());
            map.put("type","line");
            map.put("stack","Total");
            map.put("data",data);
            series.add(map);
        }

        Map<String,Object> map = new HashMap<>();
        map.put("name",sectionName);
        map.put("series",series);
        map.put("date",date);
        map.put("price",price);

        return new Result(200,"查询成功",map);
    }
}
